<?php
class Reale_Plugin_Module_RequestedModulePluginLoader 
    extends Zend_Controller_Plugin_Abstract
{
    protected $_modulePlugins = array();
 
    public function registerFrontControllerPlugin($module, $pluginName)
    {

        if (array_key_exists($module, $this->_modulePlugins) 
                        && is_array($this->_modulePlugins[$module])) {
 
            array_push($this->_modulePlugins[$module], $pluginName);
        } else {
            $this->_modulePlugins[$module] = array($pluginName);
        }
    }
 
    public function routeShutdown(Zend_Controller_Request_Abstract $request)
    {
        if (isset($this->_modulePlugins[$request->getModuleName()])) {
            $frontController = Zend_Controller_Front::getInstance();
            foreach ($this->_modulePlugins[$request->getModuleName()] as $pluginName) {
                $frontController->registerPlugin( new $pluginName);
            }
        }
    }
}